/* 
 * Copyright 2014-2021 UME Framework, GNU General Public License 
 */
package com.u2framework.lib.tool.gen.entity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.u2framework.lib.tool.gen.base.type.TypeMapper;
import com.u2framework.lib.tool.gen.entity.bean.BaseFieldBean;
import com.u2framework.lib.tool.gen.entity.bean.FieldDescBean;

/**
 * Entity DTO/DDL/Mapper/Service等文件生成时的配置信息类。
 *
 * @author SultansOfSwing & MaYue
 */
public class EntityConfigurator {
    /**
     * 特殊含义字段的标注定义
     */
    public static enum AdditionDefineType {
        AutoIncrement, CreatorId, UpdaterId, CreateTime, UpdateTime, UpdateVersion, LogicalDelete
    }
    /**
     * 生成文件的默认路径
     */
    private String genDir = "gen-tool/gen-output";
    /**
     * 模版默认路径
     */
    private String templatePath = "gen-tool/template/";
    /**
     * SQL Map 模版文件名
     */
    private String templateSqlMap = this.getTemplatePath() + "table-sqlmap.vm";
    /**
     * SQL DDL 模版文件名
     */
    private String templateSql = this.getTemplatePath() + "table-ddl.vm";
    /**
     * templateSqlBat
     */
    private String templateSqlBat = this.getTemplatePath() + "table-ddlbat.vm";
    /**
     * Entity DTO 模版文件名
     */
    private String templateEntity = this.getTemplatePath() + "entity.vm";
    /**
     * Entity Mapper 模版文件名
     */
    private String templateEntityMapper = this.getTemplatePath() + "entity-mapper.vm";
    /**
     * Entity Service Interface 模版文件名
     */
    private String templateCrudInterface = this.getTemplatePath() + "entity-crud-interface.vm";
    /**
     * Entity Service IMPL 模版文件名
     */
    private String templateCrudImpl = this.getTemplatePath() + "entity-crud-impl.vm";
    /**
     * 类型转换器
     */
    private TypeMapper typeMapper = new TypeMapper();
    /**
     * 数据库种类
     */
    private String databaseType;
    /**
     * 基础package名
     */
    private String basePackage;
    /**
     * Entity DTO 文件后缀名
     */
    private String genEntityExtension = "";
    /**
     * Entity Mapper JAVA 文件后缀名
     */
    private String genEntityMapperExtension = "Mapper";
    /**
     * Entity Mapper XML 文件后缀名
     */
    private String genSqlMapXmlExtension = "Mapper";
    /**
     * Entity Service Interface 文件后缀名
     */
    private String genCrudInterfaceExtension = "CrudService";
    /**
     * Entity Service IMPL 文件后缀名
     */
    private String genCrudClassExtension = "CrudServiceImpl";
    /**
     * Entity Service Controller 文件后缀名
     */
    private String genCrudApiExtension = "CrudController";
    /**
     * Entity Service package名
     */
    private String genCrudPackageExtension = "service";
    /**
     * Entity Service Controller package名
     */
    private String genCrudApiPackageExtension = "api";
    /**
     * Entity Mapper package名
     */
    private String genMapperPackageExtension = "mapper";
    /**
     * Entity DTO package名
     */
    private String genEntityPackageExtension = "";
    /**
     * 文档解析时跳过的文档名
     */
    private Set<String> ignoreSheetSet = new HashSet<>();
    /**
     * 追加全局定义的字段集合
     */
    private List<BaseFieldBean> genericColumnList = new ArrayList<>();
    /**
     * 生成Bean时是否使用Swagger注解，默认使用OpenApi注解
     */
    private boolean useSwagger2Annotation = false;
    /**
     * 是否移除布尔类型字段的is前缀
     */
    private Boolean isRemoveBooleanColumnIsPrefix = false;

    /**
     * 构造器
     *
     * @param databaseType
     * @throws IOException
     */
    public EntityConfigurator(String databaseType) throws IOException {
        this.databaseType = databaseType;
    }

    /**
     * 构造器
     *
     * @param databaseType
     * @param genDir
     * @throws IOException
     */
    public EntityConfigurator(String databaseType, String genDir) throws IOException {
        this.genDir = genDir;
        this.databaseType = databaseType.toLowerCase();
    }


    /**
     * 追加全局定义的字段接口
     *
     * @param coldId 列ID
     * @param colName 列标签
     * @param bizType 业务类型
     * @param length 长度
     * @param optimisticCheck 乐观坚持标识
     * @param additionDefineType 辅助类型定义
     */
    public void addGenericColumn(String coldId, String colName, String bizType, String length, boolean optimisticCheck, AdditionDefineType additionDefineType) {
        BaseFieldBean field = new FieldDescBean();
        field.setColId(coldId);
        field.setColName(colName);
        field.setColBizType(bizType);
        field.setColLength(length);
        field.setFlagOptimisticCheck(optimisticCheck);
        if (additionDefineType != null) {
            if (additionDefineType.equals(AdditionDefineType.AutoIncrement)) {
                field.setFlagAutoIncrement(true);
            } else if (additionDefineType.equals(AdditionDefineType.LogicalDelete)) {
                field.setFlagLogicalDelete(true);
            } else if (additionDefineType.equals(AdditionDefineType.CreatorId)) {
                field.setFlagCreatorId(true);
            } else if (additionDefineType.equals(AdditionDefineType.UpdaterId)) {
                field.setFlagUpdaterId(true);
            } else if (additionDefineType.equals(AdditionDefineType.CreateTime)) {
                field.setFlagCreateTime(true);
            } else if (additionDefineType.equals(AdditionDefineType.UpdateTime)) {
                field.setFlagUpdateTime(true);
            } else if (additionDefineType.equals(AdditionDefineType.UpdateVersion)) {
                field.setFlagUpdateVersion(true);
            }
        }
        genericColumnList.add(field);
    }

    /**
     * @return the genDir
     */
    public String getGenDir() {
        return genDir;
    }

    /**
     * @param genDir the genDir to set
     */
    public void setGenDir(String genDir) {
        this.genDir = genDir;
    }

    /**
     * @return the templatePath
     */
    public String getTemplatePath() {
        return templatePath;
    }

    /**
     * @param templatePath the templatePath to set
     */
    public void setTemplatePath(String templatePath) {
        this.templatePath = templatePath;
    }

    /**
     * @return the templateSqlMap
     */
    public String getTemplateSqlMap() {
        return templateSqlMap;
    }

    /**
     * @param templateSqlMap the templateSqlMap to set
     */
    public void setTemplateSqlMap(String templateSqlMap) {
        this.templateSqlMap = templateSqlMap;
    }

    /**
     * @return the templateSql
     */
    public String getTemplateSql() {
        return templateSql;
    }

    /**
     * @param templateSql the templateSql to set
     */
    public void setTemplateSql(String templateSql) {
        this.templateSql = templateSql;
    }

    /**
     * @return the templateSqlBat
     */
    public String getTemplateSqlBat() {
        return templateSqlBat;
    }

    /**
     * @param templateSqlBat the templateSqlBat to set
     */
    public void setTemplateSqlBat(String templateSqlBat) {
        this.templateSqlBat = templateSqlBat;
    }

    /**
     * @return the templateEntity
     */
    public String getTemplateEntity() {
        return templateEntity;
    }

    /**
     * @param templateEntity the templateEntity to set
     */
    public void setTemplateEntity(String templateEntity) {
        this.templateEntity = templateEntity;
    }

    /**
     * @return the templateEntityMapper
     */
    public String getTemplateEntityMapper() {
        return templateEntityMapper;
    }

    /**
     * @param templateEntityMapper the templateEntityMapper to set
     */
    public void setTemplateEntityMapper(String templateEntityMapper) {
        this.templateEntityMapper = templateEntityMapper;
    }

    /**
     * @return the templateCrudInterface
     */
    public String getTemplateCrudInterface() {
        return templateCrudInterface;
    }

    /**
     * @param templateCrudInterface the templateCrudInterface to set
     */
    public void setTemplateCrudInterface(String templateCrudInterface) {
        this.templateCrudInterface = templateCrudInterface;
    }

    /**
     * @return the templateCrudImpl
     */
    public String getTemplateCrudImpl() {
        return templateCrudImpl;
    }

    /**
     * @param templateCrudImpl the templateCrudImpl to set
     */
    public void setTemplateCrudImpl(String templateCrudImpl) {
        this.templateCrudImpl = templateCrudImpl;
    }

    /**
     * @return the typeMapper
     */
    public TypeMapper getTypeMapper() {
        return typeMapper;
    }

    /**
     * @param typeMapper the typeMapper to set
     */
    public void setTypeMapper(TypeMapper typeMapper) {
        this.typeMapper = typeMapper;
    }

    /**
     * @return the databaseType
     */
    public String getDatabaseType() {
        return databaseType;
    }

    /**
     * @param databaseType the databaseType to set
     */
    public void setDatabaseType(String databaseType) {
        this.databaseType = databaseType;
    }

    /**
     * @return the basePackage
     */
    public String getBasePackage() {
        return basePackage;
    }

    /**
     * @param basePackage the basePackage to set
     */
    public void setBasePackage(String basePackage) {
        this.basePackage = basePackage;
    }

    /**
     * @return the genEntityExtension
     */
    public String getGenEntityExtension() {
        return genEntityExtension;
    }

    /**
     * @param genEntityExtension the genEntityExtension to set
     */
    public void setGenEntityExtension(String genEntityExtension) {
        this.genEntityExtension = genEntityExtension;
    }

    /**
     * @return the genEntityMapperExtension
     */
    public String getGenEntityMapperExtension() {
        return genEntityMapperExtension;
    }

    /**
     * @param genEntityMapperExtension the genEntityMapperExtension to set
     */
    public void setGenEntityMapperExtension(String genEntityMapperExtension) {
        this.genEntityMapperExtension = genEntityMapperExtension;
    }

    /**
     * @return the genSqlMapXmlExtension
     */
    public String getGenSqlMapXmlExtension() {
        return genSqlMapXmlExtension;
    }

    /**
     * @param genSqlMapXmlExtension the genSqlMapXmlExtension to set
     */
    public void setGenSqlMapXmlExtension(String genSqlMapXmlExtension) {
        this.genSqlMapXmlExtension = genSqlMapXmlExtension;
    }

    /**
     * @return the genCrudInterfaceExtension
     */
    public String getGenCrudInterfaceExtension() {
        return genCrudInterfaceExtension;
    }

    /**
     * @param genCrudInterfaceExtension the genCrudInterfaceExtension to set
     */
    public void setGenCrudInterfaceExtension(String genCrudInterfaceExtension) {
        this.genCrudInterfaceExtension = genCrudInterfaceExtension;
    }

    /**
     * @return the genCrudClassExtension
     */
    public String getGenCrudClassExtension() {
        return genCrudClassExtension;
    }

    /**
     * @param genCrudClassExtension the genCrudClassExtension to set
     */
    public void setGenCrudClassExtension(String genCrudClassExtension) {
        this.genCrudClassExtension = genCrudClassExtension;
    }

    /**
     * @return the genCrudApiExtension
     */
    public String getGenCrudApiExtension() {
        return genCrudApiExtension;
    }

    /**
     * @param genCrudApiExtension the genCrudApiExtension to set
     */
    public void setGenCrudApiExtension(String genCrudApiExtension) {
        this.genCrudApiExtension = genCrudApiExtension;
    }

    /**
     * @return the genCrudPackageExtension
     */
    public String getGenCrudPackageExtension() {
        return genCrudPackageExtension;
    }

    /**
     * @param genCrudPackageExtension the genCrudPackageExtension to set
     */
    public void setGenCrudPackageExtension(String genCrudPackageExtension) {
        this.genCrudPackageExtension = genCrudPackageExtension;
    }

    /**
     * @return the genCrudApiPackageExtension
     */
    public String getGenCrudApiPackageExtension() {
        return genCrudApiPackageExtension;
    }

    /**
     * @param genCrudApiPackageExtension the genCrudApiPackageExtension to set
     */
    public void setGenCrudApiPackageExtension(String genCrudApiPackageExtension) {
        this.genCrudApiPackageExtension = genCrudApiPackageExtension;
    }

    /**
     * @return the genMapperPackageExtension
     */
    public String getGenMapperPackageExtension() {
        return genMapperPackageExtension;
    }

    /**
     * @param genMapperPackageExtension the genMapperPackageExtension to set
     */
    public void setGenMapperPackageExtension(String genMapperPackageExtension) {
        this.genMapperPackageExtension = genMapperPackageExtension;
    }

    /**
     * @return the genEntityPackageExtension
     */
    public String getGenEntityPackageExtension() {
        return genEntityPackageExtension;
    }

    /**
     * @param genEntityPackageExtension the genEntityPackageExtension to set
     */
    public void setGenEntityPackageExtension(String genEntityPackageExtension) {
        this.genEntityPackageExtension = genEntityPackageExtension;
    }

    /**
     * @return the ignoreSheetSet
     */
    public Set<String> getIgnoreSheetSet() {
        return ignoreSheetSet;
    }

    /**
     * @param ignoreSheetSet the ignoreSheetSet to set
     */
    public void setIgnoreSheetSet(Set<String> ignoreSheetSet) {
        this.ignoreSheetSet = ignoreSheetSet;
    }

    /**
     * @return the genericColumnList
     */
    public List<BaseFieldBean> getGenericColumnList() {
        return genericColumnList;
    }

    /**
     * @param genericColumnList the genericColumnList to set
     */
    public void setGenericColumnList(List<BaseFieldBean> genericColumnList) {
        this.genericColumnList = genericColumnList;
    }

    /**
     * @return the useSwagger2Annotation
     */
    public boolean isUseSwagger2Annotation() {
        return useSwagger2Annotation;
    }

    /**
     * @param useSwaggerAnnotation the useSwagger2Annotation to set
     */
    public void setUseSwagger2Annotation(boolean useSwaggerAnnotation) {
        this.useSwagger2Annotation = useSwaggerAnnotation;
    }

    public Boolean getRemoveBooleanColumnIsPrefix() {
        return isRemoveBooleanColumnIsPrefix;
    }

    public void setRemoveBooleanColumnIsPrefix(Boolean removeBooleanColumnIsPrefix) {
        isRemoveBooleanColumnIsPrefix = removeBooleanColumnIsPrefix;
    }
}
